const { Notification } = require('electron')


export function updateTicketInterval(ticketArray, store, key) {
    let interval = null;
    if (ticketArray || ticketArray.size() > 0) {
        interval = createInterval(store, key)
    }else{
        clearInterval(interval)
    }

}

function createInterval(store, key) {
    return setInterval(() => {
        let ticketArray = JSON.parse(store.get(key))
        ticketArray.forEach(ed => {
            if(!ed.alreadyRemind && (ed.end_time - 120  ) <= new Date().getTime() / 1000){
                sendNotifation(ed)
                ed.alreadyRemind = true
            }
        })
        store.set(key, JSON.stringify(ticketArray))
    }, 1000)
}

function sendNotifation(el) {
    let option = {
        title: "小熊抢外观",
        body: `您想抢的外观${el.info}，将在两分钟之后进入在售期`,
    }
    new Notification(option).show()
}